import Vue from 'vue'
import Vuex from 'vuex'
import {ACCESS_TOKEN, ADMIN_INFO} from '../store/mutation-types'

Vue.use(Vuex)
export default new Vuex.Store({
  state: {
    screenHeight: document.documentElement.clientHeight,
    screenWidth: document.documentElement.clientWidth,
    tabSelected: '',
    adminInfo: {}
  },
  getters: {},
  mutations: {},
  actions: {
    // 登出
    Logout ({commit, state}) {
      return new Promise((resolve) => {
        Vue.prototype.http.post('upmsApi', '/admin/login/logout', {
          token: Vue.ls.get(ACCESS_TOKEN)
        }).then((res) => {
          setTimeout(() => {
            window.location.reload()
          }, 1500)
        }).catch(() => {

        }).finally(() => {
          Vue.ls.remove(ACCESS_TOKEN)
          Vue.ls.remove(ADMIN_INFO)
        })
      })
    }

  }
})
